﻿using LJX.SmartPark.Common.ResponseOutput;
using LJX.SmartPark.Domain.SysManage;
using LJX.SmartPark.Service.SysManage;
using LJX.SmartPark.Service.SysManage.Menu;
using LJX.SmartPark.Service.SysManage.Menu.Dto;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace LJX.SmartPark.WebApi.Controllers.SysManage
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = "SysManage")]
    public class SysManageController : ControllerBase
    {
        private readonly IMenuManageService _menuManageService;

        private readonly IRoleManageService _roleManageService;

        private readonly IUserManageService _userManageService;

        private readonly IDepartManageService _departManageService;

        private readonly IRoleMenuService _roleMenuService;


        public SysManageController(IMenuManageService menuManageService, IRoleManageService roleManageService, IUserManageService userManageService, IDepartManageService departManageService, IRoleMenuService roleMenuService)
        {
            _menuManageService = menuManageService;
            _roleManageService = roleManageService;
            _userManageService = userManageService;
            _departManageService = departManageService;
            _roleMenuService = roleMenuService;
        }

        #region 菜单管理

        /// <summary>
        /// 菜单添加同级子级
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public Response<int> AddMenuManageAsync(MenuManage input)
        {
            var menus = _menuManageService.AddMenuManageAsync(input);
            return menus.Result;
        }

        /// <summary>
        /// 修改菜单
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public Response<int> UpdateMenuManageAsync(MenuManage input)
        {
            var menus = _menuManageService.UpdateMenuManageAsync(input);
            return menus.Result;
        }

        /// <summary>
        /// 获取菜单信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public Response<List<MenuManageDto>> GetMenuManage()
        {
            var menus = _menuManageService.GetMenuManage();
            return menus.Result;
        }
        
        /// <summary>
        /// 获取菜单信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public Response<List<MenuManage>> GetMenuManages()
        {
            var menus = _menuManageService.GetMenuManages();
            return menus.Result;
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<Response<bool>> PutUpdateTricolourLight(MenuManage input)
        {
            var result = _menuManageService.PutMenuManage(input);

            return result;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public Response<List<MenuManage>> GetTricolourLightAsync()
        {
            var result = _menuManageService.GetMenuManageAsync();
            return result.Result;
        }

        #endregion

        #region 在线用户

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public List<RoleMenu> GetRoleMenuByIdAsync(RoleManage input)
        {
            var result = _roleMenuService.GetRoleMenuByIdAsync(input);
            return result;
        }

        /// <summary>
        /// 角色授权菜单
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public bool PostAddRoleMenu(rolemenu input)
        {
            return _roleMenuService.PostAddRoleMenu(input);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public object GetTreeMenuManageAsync()
        {
            return _menuManageService.GrtTreeMenuManage();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public Response<List<DepartManage>> GetDepartManageAsync()
        {
            var result = _departManageService.GetDepartManageAsync();
            return result.Result;
        }


        /// <summary>
        /// 修改用户在线状态
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<Response<bool>> PutUpdateUserManageFalse(UserManage input)
        {
            var result = _userManageService.PutUpdateUserManageFalse(input);

            return result;

        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public Response<List<UserManage>> GetUserManageAsync(UserManageForm form)
        {
            var result = _userManageService.GetUserManageAsync(form);
            return result.Result;
        }

        #endregion

        #region 角色管理

        /// <summary>
        /// 添加角色
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<Response<bool>> PostAddRoleManage(RoleManage input)
        {
            var result = _roleManageService.PostAddRoleManage(input);
            return result;
        }

        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="input"></param>
        [HttpDelete]
        public Task<Response<bool>> DeleteById(RoleManage input)
        {
            var result = _roleManageService.DeleteByIdAsync(input);
            return result;
        }

        /// <summary>
        /// 修改角色
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<Response<bool>> PutUpdateRoleManage(RoleManage input)
        {
            var result = _roleManageService.PutUpdateRoleManage(input);

            return result;

        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public Response<List<RoleManage>> GetRoleManageAsync(RoleForm form)
        {
            var result = _roleManageService.GetRoleManageAsync(form);
            return result.Result;
        }
        #endregion
    }
}
